package com.qf.six.ssm.service.clientDetail.impl;


import com.qf.six.ssm.commen.exception.ServiceException;
import com.qf.six.ssm.commen.request.ClientDetailParam;
import com.qf.six.ssm.commen.request.ClientDetailRequestParam;
import com.qf.six.ssm.commen.vo.ResponseCode;
import com.qf.six.ssm.entity.ClientDetail;
import com.qf.six.ssm.mapper.clientDetail.ClientDetailMapper;
import com.qf.six.ssm.service.clientDetail.ClientDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZL
 */
@Service
public class ClientDetailServiceImpl implements ClientDetailService {
    @Resource
    ClientDetailMapper clientDetailMapper;

    @Override
    public List<ClientDetail> selectAll() {
        List<ClientDetail> list = clientDetailMapper.select();
        if(list.size() > 0){
            return list;
        } else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public ClientDetail selectById(String id) {
        ClientDetail clientDetail = clientDetailMapper.selectById(id);
        if(clientDetail != null){
            return clientDetail;
        } else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public int updateConsumer(ClientDetailParam clientDetailParam) {
        Integer count = clientDetailMapper.updateConsumer(clientDetailParam);
        if(count > 0){
            return count;
        } else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public int insert(ClientDetailRequestParam param) {
        Integer count = clientDetailMapper.insertConsumer(param);
        if(count > 0){
            return count;
        } else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public int insertDetail(String username) {
        int counnt = clientDetailMapper.insertClientUsername(username);
        if(counnt > 0){
            return counnt;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }
}
